#ifndef  G4ImproveHit_h
#define  G4ImproveHit_h 1

#include "G4VHit.hh"                // G4Hit方法类
#include "G4THitsCollection.hh"     // 管理多个命中对象
#include "G4Allocator.hh"           // 内存分配器
#include "G4ThreeVector.hh"         // 三位向量类
#include "tls.hh"                   // 线程与内存管理

class G4ImproveHit : public G4VHit{
public:
    G4ImproveHit() = default;
    G4ImproveHit(const G4ImproveHit&) = default;
    ~G4ImproveHit() override = default;

    // 操作符改写
    G4ImproveHit & operator=(const G4ImproveHit &) = default;     // 让G4ImproveHit可以通过赋值操作符进行复制
    G4bool operator==(const G4ImproveHit &) const;                // 相等操作符重载，使两个G4ImproveHit可以比较是否相等。

    // inline关键字表示该函数的定义可能在本头文件中直接实现。
    inline void* operator new(size_t);          // 声明了一个自定义的 new 操作符，用于分配内存
    inline void  operator delete(void*);        // 声明了一个自定义的 delete 操作符，用于释放内存

    // 数据打印与绘制方法
    void Draw()  override;
    void Print() override;

    // 数据设置方法
    void SetEventID     (G4int          event)      {fEventID = event;};
    void SetTrackID     (G4int          track)      {fTrackID = track;};
    void SetChamberNb   (G4int          chamb)      {fChamberNb = chamb;};
    void SetEdep        (G4double       de)         {fEdep = de;};
    void SetPos         (G4ThreeVector  xyz)    {fPos = xyz;};

    // 数据获取方法
    G4int           GetEventID()    const       {return fEventID;};
    G4int           GetTrackID()    const       {return fTrackID;};
    G4int           GetChamberNb()  const       {return fChamberNb;};
    G4double        GetEdep()       const       {return fEdep;};
    G4ThreeVector   GetPos()        const       {return fPos;};

private:
    G4int           fEventID = 0;           // event的ID
    G4int           fTrackID = -1;          // 粒子标识符
    G4int           fChamberNb = -1;        // 探测器编号
    G4double        fEdep = .0;             // 能量沉积
    G4ThreeVector   fPos;                   // 粒子位置

};

// 重定义G4THitsCollection的关键字（使用更方便） 相当于define或者typedefine
using G4ImproveHitsCollection = G4THitsCollection<G4ImproveHit>;

// 外部定义的Hit的分配器,用于管理多线程运行
extern G4ThreadLocal G4Allocator<G4ImproveHit>* G4ImproveHitAllocator;

// new操作符的重载实现
inline void* G4ImproveHit::operator new(size_t)
{
  if(!G4ImproveHitAllocator)
      G4ImproveHitAllocator = new G4Allocator<G4ImproveHit>;
  return (void *) G4ImproveHitAllocator->MallocSingle();
}
// delete操作符的重载实现
inline void G4ImproveHit::operator delete(void *hit)
{
  G4ImproveHitAllocator->FreeSingle((G4ImproveHit*) hit);
}

#endif
